package com.briup.pts.web.controller;

import com.briup.pts.entity.ManagerFenceHouse;
import com.briup.pts.entity.ManagerHurdles;
import com.briup.pts.mapper.ManagerHurdlesMapper;
import com.briup.pts.result.Result;
import com.briup.pts.service.HurdlesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "栏圈管理模块")
@RestController
@RequestMapping("/hurdle")
public class HurdleController {
    @Autowired
    HurdlesService hurdlesService;

    @GetMapping("/queryAllMax")
    public Result queryAllMax() {
        return Result.success(hurdlesService.findAllMax());
    }

    @ApiOperation("查询所有栏圈带分页带条件")
    @GetMapping
    public Result findByPage(@RequestParam Integer pageNum,
                             @RequestParam Integer pageSize,
                             String hName, Integer hMax, String fhName, String hEnable) {
        return Result.success(hurdlesService.findByPage(pageNum, pageSize, hName, hMax, fhName, hEnable));
    }

    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody ManagerHurdles managerHurdles) {
        hurdlesService.saveOrUpdate(managerHurdles);
        return Result.success();
    }

    @PutMapping("/{hId}/{hEnable}")
    public Result modifyStatus(@PathVariable String hId,
                               @PathVariable String hEnable) {
        hurdlesService.modifyStatus(hId, hEnable);
        return Result.success();
    }

    @PutMapping
    public Result modifyStatusBatch(@RequestBody List<Map<String, String>> idAndStatus) {
        hurdlesService.modifyStatusBatch(idAndStatus);
        return Result.success();
    }

    @DeleteMapping("/deleteById/{hId}")
    public Result removeByFhId(@PathVariable String hId){
        hurdlesService.removeById(hId);
        return Result.success();
    }

    @DeleteMapping("/deleteByIdAll")
    public Result removeBatch(@RequestBody List<String> ids){
        hurdlesService.removeBatch(ids);
        return Result.success();
    }

    @ApiOperation("查询所有可用且未满栏圈")
    @GetMapping("/queryAllEnable")
    public Result queryAllEnable(){
        return Result.success(hurdlesService.findAllEnable());
    }


}
